import java.util.Arrays;

public class LeetCode704 {
    public int search(int[] nums, int target) {

        int index = Arrays.binarySearch(nums, target);

        return index;
    }

    public int search2(int[] nums, int target) {
        int index = -1;

        if (nums != null && nums.length > 0){
            int left = 0;
            int right = nums.length - 1;

            while (left <= right){
                int mid = (right + left)/2;
                int midNum = nums[mid];
                if(midNum > target){
                    right = mid;
                }else if (midNum < target){
                    left = mid;
                }else {
                    return mid;
                }
            }
        }


        return index;
    }
}
